package edu.mq.itec814

import scala.actors.Actor
import scala.actors.Actor._

class MessageSender (list : List[Data]) extends Actor {

	var isDone = false
	var grandTotal = 0
	var startTime = System.currentTimeMillis()
	var endTime = System.currentTimeMillis()
	
	def doComputation() {
		startTime = System.currentTimeMillis()
	  val worker = new MessageReceiver(this)
		worker.start()
		list foreach { item => worker ! item }
		worker ! Stop
	}
	
	def act() {
		loop {
			react {
				case computedValue : Int =>
		    		grandTotal += computedValue
				case Stop =>
		    		//println("Grand Total = " + grandTotal)
		    		endTime = System.currentTimeMillis()
		    		println("Scala Actors " + (endTime - startTime) + " (ms)")
			}
		}
	  
	}
  
}